#Region " Imports "

#End Region

Partial Class Usercontrols_ControlPanel_ProfileView
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "

	Protected m_UserName As String

#End Region

#Region " Page Events "

	Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
		Me.MessageLabel = Me.uxMessagesLabel
	End Sub

	Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

		SetPageTitle("Profile Viewer")

		If IsUserAuthenticated = True Then
			GetQueryStringValues()

			If Me.Page.IsPostBack = False Then
				If HideProfile(m_UserName) = False Then
					LoadPage()
					LoadAvatar(Me.uxAvatarImage, m_UserName, False)
					GetRolesForUser()
				Else
					Me.uxMessagesLabel.Text = Resources.Resource.UserHideProfile.ToString
					Me.uxEmailButton.Visible = False
					Me.uxPrivateMessageButton.Visible = False
				End If
			End If

			If HideProfile(m_UserName) = False Then
				Me.uxMemberPanel.Visible = ShowControls(SecurityMask.Member, True)
			End If

			If m_UserName.Trim.ToLower = CurrentUser.Trim.ToLower Then
				'Me.uxUserInfoLabel.Text = String.Format("<a href=""{0}.aspx?pid=cp_profile"">{1}</a> | ", AppPage, HttpContext.Current.User.Identity.Name.Trim)
				Me.uxProfilHyperLink.NavigateUrl = String.Format("{0}.aspx?pid=cp_profile", AppPage)
				Me.uxProfilHyperLink.Text = Resources.Resource.ManageMyProfile.ToString.Trim
				Me.uxProfilHyperLink.Visible = True
			End If

		Else
			Me.uxMemberPanel.Visible = ShowControls(SecurityMask.Member, True)
		End If

	End Sub

#End Region

#Region " Save Data "



#End Region

#Region " Load Data "

	Private Sub LoadPage()
		Me.uxUserNameLabel.Text = Membership.GetUser(m_UserName).UserName.ToString
		Me.uxEmailTextLabel.Text = Membership.GetUser(m_UserName).Email.ToString
		Me.uxJoinedOnLabel.Text = Membership.GetUser(m_UserName).CreationDate
		Me.uxLastVisitLabel.Text = Membership.GetUser(m_UserName).LastLoginDate

		If String.IsNullOrEmpty(Profile.GetProfile(m_UserName).User.Website) Then
			Me.uxWebButton.Visible = False
		End If

		With Me.uxRolesCheckBoxList
			.DataSource = Roles.GetAllRoles
			.DataBind()
			.DataTextField = "Item"
			.DataValueField = "Item"
		End With

		If HideEmail(m_UserName) Then
			Me.uxEmailTextLabel.Visible = False
			Me.uxEmailButton.Visible = False
		End If

	End Sub

#End Region

#Region " Form Controls Events "

	Protected Sub uxPrivateMessageButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxPrivateMessageButton.Click
		Response.Redirect(String.Format("{0}.aspx?pid=msg_messagesystem&userid={1}", AppPage, m_UserName))
	End Sub

	Protected Sub uxEmailButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxEmailButton.Click
		LoadEmail()
	End Sub

	Protected Sub uxWebButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxWebButton.Click
		Response.Redirect(String.Format("{0}", CheckLink(Profile.GetProfile(m_UserName).User.Website)))
	End Sub

#End Region

#Region " Helpers and Methods "

	Protected Sub GetQueryStringValues()
		m_UserName = GetStringFromQueryString("UserID")
	End Sub

	Protected Function HideProfile(ByVal UserName As String) As Boolean
		If Profile.GetProfile(Membership.GetUser(UserName).UserName.ToString).User.DisplayHideProfile = True Then
			Return True
		End If
		If Profile.GetProfile(Membership.GetUser(UserName).UserName.ToString).User.DisplayHideProfile = False Then
			Return False
		End If
	End Function

	Protected Function HideEmail(ByVal UserName As String) As Boolean
		If Profile.GetProfile(Membership.GetUser(UserName).UserName.ToString).User.DisplayHideEmail = True Then
			Return True
		End If
		If Profile.GetProfile(Membership.GetUser(UserName).UserName.ToString).User.DisplayHideEmail = False Then
			Return False
		End If
	End Function

	Private Sub GetRolesForUser()
		Dim Role As New Object
		Dim iI As Integer

		For iI = 0 To Roles.GetAllRoles.Length - 1
			For Each Role In Roles.GetRolesForUser(m_UserName)
				If Me.uxRolesCheckBoxList.Items(iI).Value = Role.ToString Then
					Me.uxRolesCheckBoxList.Items(iI).Selected = True
				End If
			Next
		Next

	End Sub

	Private Sub LoadEmail()

		If UseClientEmail = True Then
			SendMailUsingClient(Membership.GetUser(m_UserName).Email.ToString, "", "")
		Else
			ScriptManager.RegisterStartupScript(uxEmailButton, Me.GetType(), "email", "fPopUpWin('" & String.Format("{0}.aspx?pid=msg_email&popup=1&userid={1}", AppPage, Replace(m_UserName, "\", "\\")) & "','email',0 , 1, 1,800,600, 0);", True)
		End If
	End Sub

#End Region

End Class
